package com.bw.mallshop.mvvm.view;

import android.os.Bundle;

import androidx.annotation.Nullable;

import com.bw.common.mvvm.view.BaseActivity;
import com.bw.mallshop.BR;
import com.bw.mallshop.R;
import com.bw.mallshop.databinding.ActivityConfirmOrderBinding;
import com.bw.mallshop.entity.CarListEntity;
import com.bw.mallshop.entity.ShipAddress;
import com.bw.mallshop.field.EventAction;
import com.bw.mallshop.mvvm.viewmodel.ConfirmOrderViewModel;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;

public class ConfirmOrderActivity extends BaseActivity<ActivityConfirmOrderBinding, ConfirmOrderViewModel> {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EventBus.getDefault().register(this);
        int orderId = getIntent().getExtras().getInt("orderId");
        ArrayList<CarListEntity.Values> listEntities = (ArrayList<CarListEntity.Values>) getIntent().getExtras().getSerializable("goodsList");
        vm.orderId = orderId;
        vm.listEntities = listEntities;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void refreshOrderState(EventAction action){
        if (action.action.equals("9000")){
            //支付宝支付成功->调用vm层中获取订单支付收款状态接口-》fwq校验是否收到钱
            vm.checkOrder();
        }else if (action.action.equals("sel_ship")){
            ShipAddress shipAddress = (ShipAddress) action.obj;
            vm.shipname.set(shipAddress.ship_user_name);
            vm.shipaddress.set(shipAddress.ship_address);
        }
    }

    @Override
    protected int createvariableId() {
        return BR.vm;
    }

    @Override
    public int bindlayout() {
        return R.layout.activity_confirm_order;
    }
}
